/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.common.query.expression;

import java.util.Collection;

/**
 * <pre>
 * 
 * empty or null 表达式
 * 
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class EmptyOrNullExpression implements ParameterCriterion {

	private boolean useAlias;
	private String operator;
	private String propertyName;

	private EmptyOrNullExpression(boolean useAlias, String operator, String propertyName) {
		this.useAlias = useAlias;
		this.operator = operator;
		this.propertyName = propertyName;
	}

	public static EmptyOrNullExpression getEmptyExpression(String propertyName) {
		return new EmptyOrNullExpression(true, ISEMPTY, propertyName);
	}

	public static EmptyOrNullExpression getNullExpression(String propertyName) {
		return new EmptyOrNullExpression(true, ISNULL, propertyName);
	}

	public static EmptyOrNullExpression getNotEmptyExpression(String propertyName) {
		return new EmptyOrNullExpression(true, ISNOTEMPTY, propertyName);
	}

	public static EmptyOrNullExpression getNotNullExpression(String propertyName) {
		return new EmptyOrNullExpression(true, ISNOTNULL, propertyName);
	}

	public static EmptyOrNullExpression getEmptyInornateExpression(String propertyName) {
		return new EmptyOrNullExpression(false, ISEMPTY, propertyName);
	}

	public static EmptyOrNullExpression getNullInornateExpression(String propertyName) {
		return new EmptyOrNullExpression(false, ISNULL, propertyName);
	}

	public static EmptyOrNullExpression getNotEmptyInornateExpression(String propertyName) {
		return new EmptyOrNullExpression(false, ISNOTEMPTY, propertyName);
	}

	public static EmptyOrNullExpression getNotNullInornateExpression(String propertyName) {
		return new EmptyOrNullExpression(false, ISNOTNULL, propertyName);
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.common.query.expression.ParameterCriterion#getJpql(java.lang.
	 *      StringBuilder)
	 */
	@Override
	public StringBuilder getJpql(StringBuilder jpql, String alias) {
		jpql.append(AND);
		if (useAlias) {
			jpql.append(alias);
		}
		jpql.append(propertyName);
		jpql.append(operator);
		return jpql;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.common.query.expression.ParameterCriterion#getParameters(java.util.
	 *      Collection)
	 */
	@Override
	public Collection<Object> getParameters(Collection<Object> parameters) {
		return parameters;
	}

}
